package by.grsu.epam.dao.entitiesdao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import by.grsu.epam.dao.GenericDAOImpl;
import by.grsu.epam.dao.entitiesdao.AccountDAO;
import by.grsu.epam.domain.account.Account;

@Repository
public class AccountDAOImpl extends GenericDAOImpl<Account, Long> implements AccountDAO {
	
	public AccountDAOImpl(){
		super(Account.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional
	public List<Account> findBySubscriberUsername(String username) {
		Criteria cr = getSession().createCriteria(Account.class, "account");
		cr.createAlias("subscriber", "subscriber");
		cr.add(Restrictions.like("subscriber.username", username));
        return (List<Account>) cr.list();
	}
}
